package com.qyy.springblog.service;


import com.qyy.springblog.mapper.BlogMapper;
import com.qyy.springblog.mapper.UserMapper;
import com.qyy.springblog.model.BlogInfo;
import com.qyy.springblog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BlogMapper blogMapper;
    public UserInfo queryUserByName(String userName) {
        return userMapper.selectByName(userName);
    }

    public UserInfo queryUserById(Integer userId) {
        return userMapper.selectById(userId);
    }

    public UserInfo getAuthorInfoByBlogId(Integer blogId) {
        //1.根据博客Id，获取作者Id
        //2.根据作者Id，获取作者信息
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if(blogInfo ==null || blogInfo.getUserId()<1){
            return null;
        }
        return userMapper.selectById(blogInfo.getUserId());
    }

    public Integer insert(UserInfo user) {
        return userMapper.insert(user);
    }
}
